package whr.modules.assets.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import whr.modules.assets.entity.ScrapEntity;
import whr.modules.assets.service.ScrapService;
import whr.common.utils.PageUtils;
import whr.common.utils.R;



/**
 * 
 *
 * @author liuli
 * @email 2547121830.com
 * @date 2024-09-23 11:36:58
 */
@RestController
@RequestMapping("assets/scrap")
public class ScrapController {
    @Autowired
    private ScrapService scrapService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("assets:scrap:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = scrapService.queryByRole(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{scrapId}")
    @RequiresPermissions("assets:scrap:info")
    public R info(@PathVariable("scrapId") Long scrapId){
		ScrapEntity scrap = scrapService.getById(scrapId);

        return R.ok().put("scrap", scrap);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("assets:scrap:save")
    public R save(@RequestBody ScrapEntity scrap){
		scrapService.save(scrap);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("assets:scrap:update")
    public R update(@RequestBody ScrapEntity scrap){
		scrapService.updateById(scrap);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("assets:scrap:delete")
    public R delete(@RequestBody Long[] scrapIds){
		scrapService.removeByIds(Arrays.asList(scrapIds));

        return R.ok();
    }

}
